$(function(){
	$.ajax({
		url:'../../user/findById',
		type:'post',
		dataType:'json',
		data:{
			userId:$("#userId").val()
		},
		success:function(data){
			if(data.code==1){
				var user = data.reObj;
				$("#nickname").val(user.nickname);
				$("#phone").val(user.phone);
				$("#balance").val(user.balance);
				$("#province").val(user.province);
				$("#city").val(user.city);
				$("#myNickname").val(user.myNickname);
				$("#consignee").val(user.consignee);
				$("#consigneePhone").val(user.consigneePhone);
				$("#consigneeAddr").val(user.consigneeAddr);
			}
		}
	})
})

layui.use(['form','layer'], function(){
    $ = layui.jquery;
    var form = layui.form()
    ,layer = layui.layer;

	  //监听提交
	  form.on('submit(save)', function(data){
			$.ajax({
				url:'../../user/update',
				type:'post',
				dataType:'json',
				data:{
					id:$("#userId").val(),
					phone:$("#phone").val(),
					myNickname:$("#myNickname").val(),
					consignee:$("#consignee").val(),
					consigneePhone:$("#consigneePhone").val(),
					consigneeAddr:$("#consigneeAddr").val()
				},
				success:function(data){
					if(data.code==1){
						layer.alert("保存成功", {icon: 6},function () {
							window.parent.location.reload();
					        var index = parent.layer.getFrameIndex(window.name);
					        parent.layer.close(index);
					    });
					}else{
						
					}
				}
			});
			return false;
	  });
});
